package club.xinghe.biz;

import club.xinghe.dao.TeacherDao;
import club.xinghe.dao.TkDao;
import club.xinghe.entity.Class;
import club.xinghe.entity.Teacher;
import club.xinghe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明:对老师进行操作的业务
 *
 * @姚文斌
 * @create 2019-09-28 下午 5:35
 */
public class TeacherBiz {
    //1.老师登陆
    public Teacher teacherLogin(Teacher teacher){
        SqlSession session= SqlSessionFactoryUtil.getSqlSession();
        TeacherDao teacherDao=session.getMapper(TeacherDao.class);
        return  teacherDao.teacherLogin(teacher);
    }

    //按专业查询平均分
    public double getZyAvg(int zId,int gid,int eId){
        //获取session
        SqlSession session= SqlSessionFactoryUtil.getSqlSession();
        Map map=new HashMap();
        map.put("zId",zId);
        map.put("gid",gid);
        map.put("eId",eId);
        double count=0;
        try{
            TeacherDao teacherDao=session.getMapper(TeacherDao.class);
            count=teacherDao.getZyAvg(map);
        }finally {
            session.close();
        }
        return count;
    }

    //查询班级列表
    public List getAllClass(int zId){
        //获取session
        SqlSession session= SqlSessionFactoryUtil.getSqlSession();
        List<Class> classList=null;
        try{
            TeacherDao teacherDao=session.getMapper(TeacherDao.class);
           classList=teacherDao.getAllClass(zId);
        }finally {
            session.close();
        }
        return classList;
    }

    //查询出班级成绩列表
    public List getAllScoreByClass(int gid,int zId,int eId,int cId){
        //获取session
        SqlSession session= SqlSessionFactoryUtil.getSqlSession();
        Map map=new HashMap();
        map.put("gid",gid);
        map.put("zId",zId);
        map.put("eId",eId);
        map.put("cId",cId);
        List<Class> classList=null;
        try{
            TeacherDao teacherDao=session.getMapper(TeacherDao.class);
            classList=teacherDao.getAllScoreByClass(map);
        }finally {
            session.close();
        }
        return classList;
    }
}
